﻿@using Topro.Entity.Enum;
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="easyui-layout case" data-options="fit: true">
    <div data-options="region: 'center', border: false" style="padding:10px; overflow: hidden;">
        <div class="easyui-layout" data-options="fit: true">
            <div class="easyui-layout" data-options="fit: true">
                <!--header-->
                <div data-options="region:'north',border: false,split:true" style="height:40px;">
                    <div class="data-tools clearfix">
                        <div class="pull-left form-inline ">
                            <a class="btn btn-default btn-sm" data-href="/Car/Add" data-title="创建" data-width="430" data-height="150" onclick="return Topro.UI.View(this)"><span class="glyphicon glyphicon-plus"></span> 创建</a>
                        </div>
                        <div class="pull-right">
                            <form class="form-inline" id="searchForm">
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">From：</label>
                                    <input class="form-control wd100" name="lie" type="text" autocomplete="off">
                                </div>
                                <div class="input-group input-group-sm">
                                    <label class="input-group-addon m5_l">To：</label>
                                    <input class="form-control wd100" name="ceng" type="text" autocomplete="off">
                                </div>
                                <button type="button" class="btn btn-default btn-sm active search" id="btnSearch"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                            </form>
                        </div>
                    </div>
                </div>
                <div data-options="region:'center',split: false, border: false">
                    <!-- 表格数据 -->
                    <table id="carDG"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    var carDG = $('#carDG');

    function Tip_success(word) {
        Topro.UI.Tip_success(word);
    }

    $(function () {
        //搜索
        $(".search").click(function(){
            car.search();
        });

        car.doSearch();
    });

    var car = {
        view: function (obj) {
            Topro.UI.DialogOpen($(obj).data("href") + '?v=' + Math.random().toString(36).substr(2, 4), {
                title: $(obj).data("title"),
                width: $(obj).data("width"),
                height: $(obj).data("height")
            });
        },
        search: function () {
            //表单
            var searchform = $("#searchForm").serializeArray();
            //表单转为Json
            var queryParams = car.getJson(searchform);

            carDG.datagrid({
                queryParams: queryParams
            });

            return false;
        },
        getJson: function (array) {
            if (array != undefined && array.length > 0) {
                var json = {};
                $(array).each(function (i, v) {
                    json[v.name] = v.value;
                });
                return json;
            } else {
                return {};
            }
        },
        queryParams:function(){
            var params = {
            };

            return params;
        },
        selectProduct: function () {
            Topro.DAO.Product({
                title: '物料',
                isSingle: true,
                saveCallBack: function(rows) {

                    if(rows.length<=0){
                        window.top.$.messager.alert('提示', '请选择物料！', 'info');
                        return;
                    }else{
                        $.each(rows, function(i, item){
                            datagrid.datagrid('insertRow',{
	                            index: 0,
	                            row: item
                            })
                        });
                    }
                }
            });
        },
        doSearch: function () {
            //固定行
            var columns = [
                [
                    {
                        field: 'from',
                        title: 'From ',
                        width: 75,
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<span class='red bold'>{0}</span>".format(row.from);
                        }
                    },
                    {
                        field: 'to',
                        title: 'To ',
                        width: 75,
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<span class='red bold'>{0}</span>".format(row.from);
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        align: 'left',
                        width: 200
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        align: 'center',
                        width: 140,
                        formatter: function (value, row, index) {

                            var result = value.replace("T"," ");

                            return result;
                        }
                    }
                ]
            ];

            Topro.UI.DataGrid(carDG, {
                fit: true,
                method: "post",
                url: "@Url.Action("CommandQuery", "Car")",
                queryParams: car.queryParams(),
                idField: 'id',
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                showFooter: true,
                autoEditing: true,
                frozenColumns: null,
                columns: columns
            });
        }
    }
</script>
